package only.my.railgunys.preparation;

import only.my.railgunys.artifact.ArtifactSuitEffect;
import only.my.railgunys.artifact.imp.CrimsonWitch;
import only.my.railgunys.artifact.imp.TenacityMillelith;
import only.my.railgunys.bean.Character;
import only.my.railgunys.bean.Weapon;
import only.my.railgunys.bean.db.Scene;
import only.my.railgunys.repository.SceneRepository;
import only.my.railgunys.shooting.Ayaka;
import only.my.railgunys.shooting.Hutao;
import only.my.railgunys.shooting.Yoimiya;
import only.my.railgunys.utils.FightUtils;
import only.my.railgunys.weapon.Homa;
import only.my.railgunys.weapon.MistsplitterReforged;
import only.my.railgunys.weapon.PrimordialJadeCutter;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import static only.my.railgunys.shooting.Yoimiya.*;

@Component
public class SingleData {
    @Autowired
    SceneRepository sceneRepository;

    public void initYoimiya(){
        Yoimiya yoimiya = new Yoimiya();
        Character yoimiyaAmos = yoimiya.init90YoimiyaAmos();
//        teamIncrease(yoimiyaAmos);
        Character yoimiyaThundering = yoimiya.init90YoimiyaThundering();
//        teamIncrease(yoimiyaThundering);
        Character yoimiyaThundering22 = yoimiya.init90YoimiyaThundering();
//        teamIncrease(yoimiyaThundering22);
        Character yoimiyaAmos22 = yoimiya.init90YoimiyaAmos();
//        teamIncrease(yoimiyaAmos22);
        Character yoimiyaRust = yoimiya.init90YoimiyaRust();
//        teamIncrease(yoimiyaRust);

        Character rust2 = new Character();
        BeanUtils.copyProperties(yoimiyaRust,rust2);

        List<Character> amosCharacterList = with25wordsRetracing4(yoimiyaAmos);
        sceneRepository.saveAll(getSceneList(amosCharacterList));

        List<Character> thunderingCharacterList = with25wordsShimenawa4(yoimiyaThundering);
        sceneRepository.saveAll(getSceneList(thunderingCharacterList));

        List<Character> thunderingCharacterList22 = with25wordsShimenawa2Gladiator2(yoimiyaThundering22);
        sceneRepository.saveAll(getSceneList(thunderingCharacterList22));

        List<Character> amosCharacterList22 = with25wordsShimenawa2Gladiator2(yoimiyaAmos22);
        sceneRepository.saveAll(getSceneList(amosCharacterList22));

        List<Character> rustYoimiya = with25wordsShimenawa4(yoimiyaRust);
        sceneRepository.saveAll(getSceneList(rustYoimiya));

        List<Character> rustYoimiyaRetracing4 = with25wordsRetracing4(rust2);
        sceneRepository.saveAll(getSceneList(rustYoimiyaRetracing4));

    }
    public static void teamIncrease(Character character) {
        character.addDescription("组队");
        character.addAtk(20d); //宗室
        character.setAtk_ex(character.getAtk_ex()+1051+17.51*4); //班尼特
    }
//    @PostConstruct
    public void initAyaka(){
        Character mr = Ayaka.getNormal90();
        teamIncrease(mr);
        Character mrEmb = Ayaka.getNormal90();
        teamIncrease(mrEmb);
        Character pjc = Ayaka.getNormal90();
        teamIncrease(pjc);
        Character pjcEmb = Ayaka.getNormal90();
        teamIncrease(pjcEmb);
        List<Character> mrList = Ayaka.mrB4Dmg(mr, 1);
        sceneRepository.saveAll(getSceneList(mrList));

        List<Character> pjcList = Ayaka.pjB4Dmg(pjc, 1);
        sceneRepository.saveAll(getSceneList(pjcList));

        Weapon primordialJadeCutter = new PrimordialJadeCutter(1);
        List<Character> pjcG2b2List = Ayaka.mrB2G2mg(pjcEmb, primordialJadeCutter);
        sceneRepository.saveAll(getSceneList(pjcG2b2List));

        Weapon mr22 = new MistsplitterReforged(1);
        List<Character> mrG2b2List = Ayaka.mrB2G2mg(mrEmb, mr22);
        sceneRepository.saveAll(getSceneList(mrG2b2List));
    }
    public void initHutao(){
        Character mr = Hutao.getDoubleGeoHutao(1);
        Weapon homa = new Homa(1);
        ArtifactSuitEffect crimsonWitch = new CrimsonWitch();
        ArtifactSuitEffect tenacityMillelith = new TenacityMillelith();
        List<Character> characters = FightUtils.calcSuitIncrease(mr, homa, crimsonWitch::setEffect2Piece, crimsonWitch::setEffect4Piece,Hutao::specialIncrease);
        sceneRepository.saveAll(getSceneList(characters));
    }

    public static List<Scene> getSceneList(List<Character> list) {

        return list.stream()
                .sorted(Comparator.comparingInt(Character::getTotalDmg).reversed())
                .limit(100)
                .map(Character::toScene)
                .collect(Collectors.toList());
    }
}
